<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <%@ include file="/common/client/header.jsp" %>
    <script src="${ctx}/statics/js/manager/manager.js"></script>
</head>
<body>

<!--End Header End-->
<%@ include file="/common/manager/searchBar.jsp" %>
<div class="i_bg bg_color">
    <!--Begin 用户中心 Begin -->
    <div class="m_content">
        <%@ include file="/common/manager/leftBar.jsp" %>
        <div class="m_right" id="content">
            <div class="mem_tit">用户列表</div>
            <p align="right">
                <a href="${ctx}/manager/user/toUpdateUser.jsp"  class="add_b">添加用户</a>
                <br>
            </p>
            <br>
            <table border="0" class="order_tab" style="width:930px; text-align:center; margin-bottom:30px;"
                   cellspacing="0" cellpadding="0">
                <thead>
                <tr>
                    <td width="10%">用户名称</td>
                    <td width="10%">真实姓名</td>
                    <td width="5%">性别</td>
                    <td width="5%">类型</td>
                    <td width="5%" colspan="2">操作</td>
                </tr>


                </thead>
                <%--用户start--%>

                <%--用户end--%>
                <%--用户start--%>

                <%--用户end--%>

                <tbody id="userList">

                </tbody>
                <div id="pagination">
                    <a id="prevPage" href="#">上一页</a>
                    <span id="currentPage">1</span>
                    <a id="nextPage" href="#">下一页</a>
                </div>
            </table>
            <%@ include file="/common/client/pagerBar.jsp" %>
        </div>
    </div>
    <%@ include file="/common/client/footer.jsp" %>
</div>



<script>
    var currentPage = 1;  // 初始页码
    var pageSize = 6;    // 每页显示的项数

    function loadPage(page) {
        $.ajax({
            url: "/userList?page=" + page + "&pageSize=" + pageSize,
            method: "GET",
            success: function (data) {
                var html = "";

                // 检查是否有 pageList 属性
                if (data.pageList && data.pageList.length > 0) {
                    data.pageList.forEach(function (user) {
                        // 添加条件检查，只有当用户类型不是管理员时才追加到表格中
                        if (user.type !== 1) {
                            html += "<tr><td>" + user.account + "</td><td>" + user.nick_name + "</td><td>" + (user.gender === 1 ? "男" : "女") + "</td><td>" + (user.type === 1 ? "管理员" : "用户") + "</td><td><a href='/manager/user/toUpdateUser?userId=" + user.id + "'>修改</a></td><td><a onclick='deleteUserId(" + user.id + ")'>删除</a></td></tr>";
                        }
                    });
                } else {
                    html = "<tr><td colspan='6'>没有数据可显示</td></tr>";
                }

                // 将构建的HTML添加到表格中
                $("#userList").html(html);

                // 更新当前页码
                $("#currentPage").text(page);
            }
        });
    }

    // 初始加载第一页数据
    loadPage(currentPage);

    $("#prevPage").click(function () {
        if (currentPage > 1) {
            currentPage--;
            loadPage(currentPage);
        }
    });

    $("#nextPage").click(function () {
        currentPage++;
        loadPage(currentPage);
    });





</script>

</body>
</html>
